﻿namespace Vin.Extension.Quartz.Models;

/// <summary>
/// 任务类型
/// </summary>
public enum TaskInfoType
{
    // 泛型
    Generics = 1,

    // 程序集
    Assembly = 2,
}

/// <summary>
/// 触发器类型
/// </summary>
public enum TriggerType
{
    // 简单触发器
    Simple = 1,

    // Cron表达式触发器
    Cron = 2,
}

/// <summary>
/// 间隔类型
/// </summary>
public enum IntervalType
{
    // 秒
    Second = 1,

    // 分钟
    Minute = 2,

    // 小时
    Hour = 3,

    // 天
    Day = 4
}

/// <summary>
/// 循环类型
/// </summary>
public enum LoopType
{
    // 一次
    Once = 1,

    // 有限循环
    Finite = 2,
    
    // 无限循环
    Infinite = 3,
}

public class TaskInfo
{
    /// <summary>
    /// 任务id
    /// </summary>
    public string JobId { get; set; }

    /// <summary>
    /// 任务名称
    /// </summary>
    public string JobName { get; set; }

    /// <summary>
    /// 任务分组
    /// </summary>
    public string? JobGroup { get; set; }

    /// <summary>
    /// 任务类型
    /// </summary>
    public TaskInfoType TaskInfoType { get; set; } = TaskInfoType.Generics;

    /// <summary>
    /// 泛型类型
    /// </summary>
    public Type? JobType { get; set; }
    
    /// <summary>
    /// 程序集路径
    /// </summary>
    public string? AssemblyPath { get; set; }

    /// <summary>
    /// 程序集名称
    /// </summary>
    public string? AssemblyName { get; set; }

    /// <summary>
    /// 任务类名
    /// </summary>
    public string? ClassName { get; set; }

    /// <summary>
    /// 任务参数
    /// </summary>
    public IDictionary<string, object>? Parameters { get; set; }

    /// <summary>
    /// 触发器类型
    /// </summary>
    public TriggerType TriggerType { get; set; } = TriggerType.Simple;

    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    public DateTime? EndTime { get; set; }

    /// <summary>
    /// 间隔类型
    /// </summary>
    public IntervalType IntervalType { get; set; } = IntervalType.Second;
    
    /// <summary>
    /// 是否立即启动
    /// </summary>
    public bool? IsStartNow { get; set; }

    /// <summary>
    /// 间隔
    /// </summary>
    public int Interval { get; set; }

    /// <summary>
    /// 循环类型
    /// </summary>
    public LoopType LoopType { get; set; } = LoopType.Once;

    /// <summary>
    /// 循环次数
    /// </summary>
    public int LoopCount { get; set; }

    /// <summary>
    /// Cron表达式
    /// </summary>
    public string? CronExpression { get; set; }

    public TaskInfo(string jobId)
    {
        this.JobId = jobId;
        this.JobName = $"定时任务【{jobId}】";
    }

    public TaskInfo(string jobId, string jobName, string? jobGroup = null,
        Dictionary<string, object>? parameters = null)
    {
        this.JobId = jobId;
        this.JobName = jobName;
        this.JobGroup = jobGroup;
        this.Parameters = parameters;
    }
}